public class Solution169 {
    public int majorityElement(int[] nums) {
        int a=Integer.MIN_VALUE,ap=0;
        for (int num : nums) {
            if (ap==0){
                a=num;
                ap=1;
            }else{
                if (num==a){
                    ap++;
                }else{
                    ap--;
                }
            }
        }
        return a;
    }

    public static void main(String[] args) {
        System.out.println(new Solution169().majorityElement(new int[]{2,2,1,1,1,2,2}));
    }
}
